package app.auto.runner.base;

/**
 * Created by hp on 2018/5/11.
 * String cat
 */
public class Prt {
    private final String Prt;

    public Prt(String Prt) {
        this.Prt = Prt;
    }

    private static Prt hold;

    public static Prt newInstance(String Prt) {
        return hold = new Prt(Prt);
    }

    public static Prt hold() {
        return hold;
    }

    public int getLeng() {
        return Prt.length();
    }

    public int getAfterIndex(String whole) {
        return whole.indexOf(Prt) + getLeng();
    }

    public int getPreviousIndex(String whole) {
        return whole.indexOf(Prt);
    }

    public static Prt cat(String pre, String after, String whole) {
        String p;
        try {
            p = whole.substring(new Prt(pre).getAfterIndex(whole), new Prt(after).getPreviousIndex(whole));
        } catch (Exception e) {
            return null;
        }
        return new Prt(p).setBoundPre(pre, whole).setBoundAfter(after, whole);
    }

    public String getPrt() {
        return Prt;
    }

    public int preidx;
    public int afteridx;

    public Prt setBoundPre(String prestr, String txt) {
        Prt prt = new Prt(prestr);

        boundpreidx = prt.getAfterIndex(txt);
        return this;
    }

    public int boundpreidx;
    public int boundafteridx;


    public Prt setBoundAfter(String prestr, String txt) {
        Prt prt = new Prt(prestr);

        boundafteridx = prt.getPreviousIndex(txt);
        return this;
    }

    public int getBoundpreidx() {
        return boundpreidx;
    }

    public int getBoundafteridx() {
        return boundafteridx;
    }

    public int getPreidx() {
        return preidx;
    }

    public int getAfteridx() {
        return afteridx;
    }
}